<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>Simpla Admin</title>
		<link rel="stylesheet" href="${pageContext.request.contextPath}/backstage/resources/css/reset.css" type="text/css" media="screen" />
		<link rel="stylesheet" href="${pageContext.request.contextPath}/backstage/resources/css/style.css" type="text/css" media="screen" />
		<link rel="stylesheet" href="${pageContext.request.contextPath}/backstage/resources/css/invalid.css" type="text/css" media="screen" />
		
		<link rel="stylesheet" href="${pageContext.request.contextPath}/backstage/zTree/css/demo.css" type="text/css">
		<link rel="stylesheet" href="${pageContext.request.contextPath}/backstage/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
	
		<!--<script type="text/javascript" src="${pageContext.request.contextPath}/backstage/resources/scripts/jquery-1.3.2.min.js"></script>-->
		<script type="text/javascript" src="${pageContext.request.contextPath}/backstage/resources/scripts/jquery-1.6.min.js"></script>
		
		<script type="text/javascript" src="${pageContext.request.contextPath}/backstage/resources/scripts/simpla.jquery.configuration.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/backstage/resources/scripts/facebox.js"></script><!-- 弹出窗口 -->
		
		<!-- 树 -->
		<script type="text/javascript" src="${pageContext.request.contextPath}/backstage/zTree/js/jquery.ztree.core-3.0.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/backstage/zTree/js/jquery.ztree.excheck-3.0.js"></script>
		
		<script type="text/javascript">
			var setting = {
				check: {
					enable: true
				},
				data: {
					simpleData: {
						enable: true
					}
				}
			};
			//$('a[rel*=modal]').facebox();
			jQuery(document).ready(function($) {
  				$('a[rel*=modal]').facebox();
  				<%if(request.getAttribute("error") != null && request.getAttribute("error") != "" && !"".equals(request.getAttribute("error"))){%>
  					$("#errorA").trigger('click');
  					
  				<%}%>
			})
			
			function onClickEdit(id,name,gid){
				$("#udateid").val(id);
				$("#udatename").val(name);
				$("#udategroupId").val(gid);
			}

			function onClickEditMeta(id){
				$.getJSON("jsoncompAction.action?id=" + id,function(data){
					d = data.request;
					var zNodes = data.request;
					$.fn.zTree.init($("#treeDemo"), setting, zNodes);
					var zTree = $.fn.zTree.getZTreeObj("treeDemo");
					zTree.setting.check.chkboxType = { "Y":"ps", "N":"ps"};
					var action = '';
					var form = $("<form></form>");
			        form.attr('action',action);
			        form.attr('method','post');
			        var input = $("<input type='submit' class='button' />");
			        input.attr('value','确定');
			        input.bind('click',function(){
			        	var zTree = $.fn.zTree.getZTreeObj("treeDemo");
						var checkCount = zTree.getCheckedNodes(true);
						var mid = '';
						for(var i=0;i<checkCount.length;i++){
							var o = checkCount[i];
							if(o.id){
								if(i!=0)mid = mid + ',' + o.id;
								if(i==0)mid = o.id;
							}
						}
						form.attr('action','competenceAction!updateMenuTree.action?id=' + id + '&mid=' + mid);
			        });
			        form.append($("#treeDemo"));
			        form.append('<br>');
			        form.append('<s:hidden name="p.curPage" value="%{p.curPage}"/>');
			        form.append('<s:hidden name="p.count" value="%{p.count}"/>');
			        form.append('<s:hidden name="p.pageSize" value="%{p.pageSize}"/>');
			        form.append('<s:hidden name="p.sortOrder" value="%{p.sortOrder}"/>');
			        form.append(input);					
					jQuery.facebox(form);
				});
			}
			
			function clock(){
			    $('#facebox').fadeOut(function() {
			      	$('#facebox .content').removeClass().addClass('content');
			      	$('#facebox .loading').remove();
			    })
			    $('#facebox_overlay').fadeOut(200, function(){
			    	$("#facebox_overlay").removeClass("facebox_overlayBG")
			   		$("#facebox_overlay").addClass("facebox_hide") 
			   		$("#facebox_overlay").remove()
			    })
			}	
		</script>
	</head>
	<body>
		<div id="add" style="display: none" width="230">
			<form action="competenceAction!add.action" method="post">
				<label>中文名</label>
				<input class="text-input small-input" type="text" id="name" name="name" />
				<br/>
				<label>权限</label>
				<input class="text-input medium-input datepicker" type="text" id="groupId" name="groupId" />
				<br/>
				<br/>
				<input type="hidden" id="id" name="id" />
				<s:hidden name="p.curPage" value="%{p.curPage}"/>
				<s:hidden name="p.count" value="%{p.count}"/>
				<s:hidden name="p.pageSize" value="%{p.pageSize}"/>
				<s:hidden name="p.sortOrder" value="%{p.sortOrder}"/>
				<input class="button" type="submit" value="确定" />&nbsp;&nbsp;
				<input class="button" type="button" value="关闭" onclick="clock()"/>
			</form>
		</div>
		<div id="update" style="display: none" width="230">
			<form action="competenceAction!update.action" method="post">
				<label>中文名</label>
				<input class="text-input small-input" type="text" id="udatename" name="name" />
				<br/>
				<label>权限</label>
				<input class="text-input medium-input datepicker" type="text" id="udategroupId" name="groupId" />
				<br/>
				<br/>
				<input type="hidden" id="udateid" name="id" />
				<s:hidden name="p.curPage" value="%{p.curPage}"/>
				<s:hidden name="p.count" value="%{p.count}"/>
				<s:hidden name="p.pageSize" value="%{p.pageSize}"/>
				<s:hidden name="p.sortOrder" value="%{p.sortOrder}"/>
				<input class="button" type="submit" value="确定" />&nbsp;&nbsp;
				<input class="button" type="button" value="关闭" onclick="clock()"/>
			</form>
		</div>
		<div id="error" style="display: none">
			<label>${ error }</label>
		</div>
		<div style="display: none">
			<a id="errorA" class="button" href="#error" rel="modal">错误</a>
		</div>
		<div id="main-content">
			<div class="content-box">
				<div class="content-box-header">
					<h3>
						成员
					</h3>
					<div class="clear"></div>
				</div>
				<div class="content-box-content">
					<div class="tab-content default-tab" id="tab1">
						<table>
							<thead>
								<tr>
									<th>
										名字
									</th>
									<th>
										权限
									</th>
									<th>
										操作
									</th>
								</tr>
							</thead>
							<tfoot>
								<tr>
									<td colspan="6">
										<div class="pagination">
											<s:url id="firstPage" action="compAction.action">
												<s:param name="p.curPage" value="p.firstPage"/>
												<s:param name="p.count" value="p.count"/>
												<s:param name="p.pageSize" value="p.pageSize"/>
												<s:param name="p.sortOrder" value="p.sortOrder"/>
											</s:url>
											<s:url id="prevPage" action="compAction.action">
												<s:param name="p.curPage" value="p.prevPage"/>
												<s:param name="p.count" value="p.count"/>
												<s:param name="p.pageSize" value="p.pageSize"/>
												<s:param name="p.sortOrder" value="p.sortOrder"/>
											</s:url>
											<s:url id="nextPage" action="compAction.action">
												<s:param name="p.curPage" value="p.nextPage"/>
												<s:param name="p.count" value="p.count"/>
												<s:param name="p.pageSize" value="p.pageSize"/>
												<s:param name="p.sortOrder" value="p.sortOrder"/>
											</s:url>
											<s:url id="lastPage" action="compAction.action">
												<s:param name="p.curPage" value="p.lastPage"/>
												<s:param name="p.count" value="p.count"/>
												<s:param name="p.pageSize" value="p.pageSize"/>
												<s:param name="p.sortOrder" value="p.sortOrder"/>
											</s:url>
											<s:if test="p != null">
												<s:a href="%{firstPage}" title="第一页">&laquo; 第一页</s:a>
											</s:if>
											<s:if test="p.hasPrePage">
												<s:a href="%{prevPage}" title="上一页">&laquo; 上一页</s:a>
											</s:if>
											<s:if test="p.countPage > 0 && p.curPage > 0">
												<s:bean name="org.apache.struts2.util.Counter" id="counter">
													<s:param name="first" value="1" />
													<s:param name="last" value="p.countPage"/>
													<s:iterator status="s">
														<s:if test="#s.index + 1 == p.curPage">
															<a href="<s:url action="compAction.action"><s:param name="p.curPage" value="#s.index + 1"/><s:param name="p.count" value="p.count"/><s:param name="p.pageSize" value="p.pageSize"/><s:param name="p.sortOrder" value="p.sortOrder"/></s:url>" class="number current" title="<s:property value="#s.index + 1"/>"><s:property value="#s.index + 1"/></a>
														</s:if>
														<s:else>
															<a href="<s:url action="compAction.action"><s:param name="p.curPage" value="#s.index + 1"/><s:param name="p.count" value="p.count"/><s:param name="p.pageSize" value="p.pageSize"/><s:param name="p.sortOrder" value="p.sortOrder"/></s:url>" class="number" title="<s:property value="#s.index + 1"/>"><s:property value="#s.index + 1"/></a>
														</s:else>
													</s:iterator>
												</s:bean>
											</s:if>
											<s:if test="p.hasNextPage">
												<s:a href="%{nextPage}" title="下一页">下一页 &raquo;</s:a>
											</s:if>
											<s:if test="p != null">
												<s:a href="%{lastPage}" title="最后一页">最后一页 &raquo;</s:a>
											</s:if>
										</div>
										<div class="clear"></div>
									</td>
								</tr>
							</tfoot>
							<tbody>
							<s:iterator var="vo" value="list" status="s">
								<tr>
									<td>${vo.name}</td>
									<td>${vo.groupId}</td>
									<td>
										<a href="#update" rel="modal" onclick="onClickEdit('${vo.id}','${vo.name}','${vo.groupId}')" title="修改"><img src="${pageContext.request.contextPath}/backstage/resources/images/icons/pencil.png" alt="修改" /></a>
										<a href="competenceAction!delete.action?id=${vo.id}&p.curPage=${p.curPage}&p.count=${p.count}&p.pageSize=${p.pageSize}&p.sortOrder=${p.sortOrder}" title="删除"><img src="${pageContext.request.contextPath}/backstage/resources/images/icons/cross.png" alt="删除" /></a>
									</td>
								</tr>
							</s:iterator>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</body>
</html>
